package checkpoint;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import org.junit.Test;

public class Checkpoint_test1 {
    @Test
    public void test() throws Exception {
        System.setProperty("HADOOP_USER_NAME","work");
        StreamExecutionEnvironment env = StreamExecutionEnvironment
                .getExecutionEnvironment()
                .setParallelism(1)
                .setStateBackend(new FsStateBackend("hdfs://node193:9000/flink/flink1"));
        env.socketTextStream("node193",9999)
                .flatMap(new FlatMapFunction<String, Tuple2<String,Integer>>() {
                    @Override
                    public void flatMap(String value, Collector<Tuple2<String, Integer>> out) throws Exception {
                        for (String s : value.split(" ")) {
                            out.collect(new Tuple2<>(s,1));
                        }
                    }
                })
                .keyBy(value -> value.f0)
                .sum(1)
                .print();
        env.execute();
    }
}
